# import os
# from transformers import SpeechT5HifiGan
#
# # -------------------------------
# # 1. 设置国内镜像源（关键步骤）
# # -------------------------------
# os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
#
# # -------------------------------
# # 2. 定义本地保存路径
# # -------------------------------
# local_vocoder_path = "./tmp/speecht5_hifigan"
# os.makedirs(local_vocoder_path, exist_ok=True)
#
# # -------------------------------
# # 3. 从镜像站下载模型并加载
# # -------------------------------
# print("📥 正在从 hf-mirror.com 下载 microsoft/speecht5_hifigan...")
# vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
#
# # -------------------------------
# # 4. 保存模型到本地
# # -------------------------------
# vocoder.save_pretrained(local_vocoder_path)
# print(f"✅ 模型已成功下载并保存到: {local_vocoder_path}")


import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
from transformers import SpeechT5HifiGan
model_path = "./tmp/speecht5_hifigan"
os.makedirs(model_path, exist_ok=True)
model = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan", torch_dtype="auto")
model.save_pretrained(model_path)


# # Load model directly
# import os
# from transformers import SpeechT5HifiGan
# # -------------------------------
# # 1. 设置国内镜像（关键：不能有空格！）
# # -------------------------------
# os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"  # ✅ 去掉空格
# # -------------------------------
# # 2. 指定本地保存路径
# # -------------------------------
# local_save_path = "./tmp/speecht5_hifigan"  # 你可以改成任意路径
# os.makedirs(local_save_path, exist_ok=True)
# # -------------------------------
# # 3. 从镜像站下载模型
# # -------------------------------
# print("📥 正在从 hf-mirror.com 下载 microsoft/speecht5_hifigan...")
# vocoder = SpeechT5HifiGan.from_pretrained(
#     "microsoft/speecht5_hifigan",
#     torch_dtype="auto"  # 自动根据训练配置设置精度
# )
# # -------------------------------
# # 4. 保存模型到你指定的文件夹
# # -------------------------------
# vocoder.save_pretrained(local_save_path)
# print(f"✅ 模型已成功下载并保存到: {os.path.abspath(local_save_path)}")